package org.learn.intermediate.homework;

public class HomeWork10 {
    public static void main(String[] args) {
        String name = "jack";
        String pwd = "123456";
        String email = "2097364285@qq.com";
        try {
            userRegister(name, pwd, email);
            System.out.println("恭喜你注册成功");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void userRegister(String name , String pwd, String email) {
        //name
        int userLength = name.length();
        if(!(userLength >= 2 && userLength <= 4)){
            throw new RuntimeException("用户名长度为2或3或4");
        }
        //pwd
        if(!(pwd.length() == 6 && isDigtal(pwd))){
            throw new RuntimeException("密码长度为6而且要求全是数字");
        }
        //email
        int i = email.indexOf('@');
        int j = email.indexOf('.');
        if(!(i > 0 && j > i)){
            throw new RuntimeException("邮箱要求含有@和.");
        }
    }
    
    //方法判断密码是否全是数字字符
    public static boolean isDigtal(String str){
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(chars[i] < '0' || chars[i] > '9'){
                return false;
            }
        }
        return true;
    }
}
